import Vue from 'vue'
import Router from 'vue-router'
import Store from './store/index'
import Index from '@/views/Index.vue'
Vue.use(Router)
const router = new Router({
  mode: 'history',
  base: process.env.BASE_URL,
  routes: [
    {
        path: '/',
        name: 'index',
        component: Index
    },
    {
        path: '/chart',
        name: 'chart',
        // route level code-splitting
        // this generates a separate chunk (about.[hash].js) for this route
        // which is lazy-loaded when the route is visited.
        component: () => import(/* webpackChunkName: "about" */ '@/views/Charts.vue')
    }
  ]
})
/**
 * 进入每个路由前的钩子函数
 */
router.beforeEach((to, from, next) => {
  // to and from are both route objects. must call `next`.
  let menuData =  [{
    code: '01',
    title: '导航一',
    children: [{
        code: '0101',
        title: '导航一-01',
        children: [{
          code: '0101-01',
          title: '首页',
          router: '/',
          name: 'index'
        },{
          code: '0101-02',
          title: '报表查询',
          router: '/chart',
          name: 'chart'
        }]
    },{
        code: '0102',
        title: '导航一-02',
         children: [{
            code: '0101-02',
            title: '选项2'
        }]
    }]
},{
    code: '02',
    title: '水果'
},{
    code: '03',
    title: '蔬菜'
}]
  /*菜单数据*/
  Store.commit('setMenuData', menuData);
  next();
})
export default router;